`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    16:22:16 05/08/2012 
// Design Name: 
// Module Name:    top_pong 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module top_pong(clk_i, rst_i, startGame_i, up_i, down_i, increase_Incrash_i, ini_speed_i,hsync_o, vsync_o,rgb_o
);
   input clk_i,rst_i,startGame_i,up_i,down_i,increase_Incrash_i;
	input  [3:0] ini_speed_i;
	output hsync_o,vsync_o;
	output [7:0] rgb_o;
	wire [9:0] ball_x_o, ball_y_o, paddle_y_o,pixel_x, pixel_y;
	wire game_Over_o,rst_syn,up_syn,down_syn,startgame_syn,hsync,vsync,video_on,p_tick_o;
	wire [7:0] graph_rgb;
	wire [5:0] speed_x, speed_y;
	assign speed_x = (increase_Incrash_i)? 6'b000111 : {2'b00, ini_speed_i};
	assign speed_y = (increase_Incrash_i)? 6'b000111 : {2'b00, ini_speed_i};
	
	reg new_frame;
	reg [20:0] contador;
	
	initial begin 
		contador =0;
		new_frame=0;
	end
	
	always @(posedge clk_i) begin 
		if (new_frame) begin
			new_frame<=0;
		end
		else if (contador==416665) begin
			new_frame<=1;
			contador<=0;
		end
		else begin
			contador<=contador+1;
		end
	end
	
	assign hsync_o=hsync;
	assign vsync_o=vsync;
	assign rgb_o = (video_on) ? graph_rgb : 8'b0;
	
	Control_Unit Pong_Control_Unit(new_frame, rst_syn, startgame_syn, up_syn, down_syn, increase_Incrash_i, speed_x, speed_y,
	ball_x_o, ball_y_o, paddle_y_o, game_Over_o);
	
	vga_sync vga (clk_i,rst_syn,hsync,vsync,video_on, p_tick_o, pixel_x, pixel_y);
	
	debouncer sync (rst_i,up_i,down_i,startGame_i,clk_i,rst_syn,up_syn,down_syn,startgame_syn);
	
	Display_Field display (game_Over_o, video_on,pixel_x, pixel_y, ball_x_o, ball_y_o, paddle_y_o,graph_rgb);

endmodule

